package com.soft.mainsite.module.show.sevice.impl;

import com.soft.mainsite.module.show.dao.ShowDao;
import com.soft.mainsite.module.show.entity.Show;
import com.soft.mainsite.module.show.sevice.ShowService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ShowServiceImpl此类用于
 *
 * @author: hujm
 * @date: 2019年09月12日 17:30
 * @remark:
 */
@Slf4j
@Service
public class ShowServiceImpl implements ShowService {

    @Autowired
    private ShowDao showDao;

    @Override
    public List<Show> findAll() {
        return showDao.findAll();
    }

    @Override
    public List<Show> findByCategoryId(Integer categoryId) {
        List<Show> showDaoAll = showDao.findAll();
        List<Show> showList = showDao.findByCategoryId(categoryId);
        if (showDaoAll.size() != 0 && showList.size() != 0){
            for (Show show : showDaoAll) {

                for (Show show1 : showList) {
                    if (show1.getShowId().equals(show.getShowId())){
                        show.setCheckStatus(1);
                        break;
                    }
                }
            }
        }
        return showDaoAll;
    }

    @Override
    public void save(List<Integer> showIds, Integer categoryId) {

        String string = StringUtils.join(showIds,",");
        showDao.save(string, categoryId);
    }

    @Override
    public int update(List<Integer> showIds, Integer categoryId) {
        String string = StringUtils.join(showIds,",");
        return showDao.update(string, categoryId);
    }
}
